home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok24.lha
/
DME
/
SRC
/
source.zoo
/
gadgets.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-07-03
|
7KB
|
256 lines
/*
** gadgets.c 1989 by Thomas Siemens and Volker Rudolph
*/
/*** included files ***/
#include "defs.h"
/*** data section ***/
SHORT BorderVectors1[] = {
0,0,
5,0,
5,5,
3,5,
6,8,
7,8,
10,5,
8,5,
8,0,
14,0,
14,10,
0,10,
0,0
};
struct Border Border1 = {
0,-1, /* XY origin relative to container TopLeft */
1,0,JAM1, /* front pen, back pen and drawmode */
13, /* number of XY vectors */
BorderVectors1, /* pointer to XY vectors */
NULL /* next border in list */
};
/* arrow down */
struct Gadget Gadget3 = {
NULL, /* next gadget */
-15,-18, /* origin XY of hit box relative to window TopLeft */
16,9, /* hit box width and height */
GRELBOTTOM+GRELRIGHT, /* gadget flags */
RELVERIFY+GADGIMMEDIATE+RIGHTBORDER, /* activation flags */
BOOLGADGET, /* gadget type flags */
(APTR)&Border1, /* gadget border or image to be rendered */
NULL, /* alternate imagery for selection */
NULL, /* first IntuiText structure */
NULL, /* gadget mutual-exclude long word */
NULL, /* SpecialInfo structure */
3, /* user-definable data */
NULL /* pointer to user-definable data */
};
SHORT BorderVectors2[] = {
0,0,
14,0,
14,10,
8,10,
8,5,
10,5,
7,2,
6,2,
3,5,
5,5,
5,10,
0,10,
0,0
};
struct Border Border2 = {
0,-1, /* XY origin relative to container TopLeft */
1,0,JAM1, /* front pen, back pen and drawmode */
13, /* number of XY vectors */
BorderVectors2, /* pointer to XY vectors */
NULL /* next border in list */
};
/* arrow up */
struct Gadget Gadget2 = {
&Gadget3, /* next gadget */
-15,11, /* origin XY of hit box relative to window TopLeft */
16,9, /* hit box width and height */
GRELRIGHT, /* gadget flags */
RELVERIFY+GADGIMMEDIATE+RIGHTBORDER, /* activation flags */
BOOLGADGET, /* gadget type flags */
(APTR)&Border2, /* gadget border or image to be rendered */
NULL, /* alternate imagery for selection */
NULL, /* first IntuiText structure */
NULL, /* gadget mutual-exclude long word */
NULL, /* SpecialInfo structure */
2, /* user-definable data */
NULL /* pointer to user-definable data */
};
struct PropInfo Gadget1SInfo = {
AUTOKNOB+FREEVERT, /* PropInfo flags */
-1,-1, /* horizontal and vertical pot values */
-1,-1, /* horizontal and vertical body values */
};
struct Image Image1 = {
0,0, /* XY origin relative to container TopLeft */
7,80, /* Image width and height in pixels */
0, /* number of bitplanes in Image */
NULL, /* pointer to ImageData */
0x0000,0x0000, /* PlanePick and PlaneOnOff */
NULL /* next Image structure */
};
/* scroll bar */
struct Gadget Gadget1 = {
&Gadget2, /* next gadget */
-15,20, /* origin XY of hit box relative to window TopLeft */
16,-39, /* hit box width and height */
GADGHBOX+GADGHIMAGE+GRELRIGHT+GRELHEIGHT, /* gadget flags */
RELVERIFY+GADGIMMEDIATE+RIGHTBORDER, /* activation flags */
PROPGADGET, /* gadget type flags */
(APTR)&Image1, /* gadget border or image to be rendered */
NULL, /* alternate imagery for selection */
NULL, /* first IntuiText structure */
NULL, /* gadget mutual-exclude long word */
(APTR)&Gadget1SInfo, /* SpecialInfo structure */
1, /* user-definable data */
NULL /* pointer to user-definable data */
};
#define GadgetList1 Gadget1
short knob_modified;
/*** code section ***/
set_prop() /* set scroll bar */
{
register ED *ep = Ep;
register struct PropInfo *pInf = &Gadget1SInfo;
register ULONG newPot,newBody;
newPot = 0xFFFF * ep->Topline / ((ep->Lines-Rows > 1) ? ep->Lines-Rows - 1 : 1);
newBody = 0xFFFF * ((Rows < ep->Lines) ? Rows : ep->Lines) / ep->Lines;
if(newPot > 0xffff)
newPot = 0xffff;
if((pInf->VertPot != newPot) || (pInf->VertBody != newBody)) {
NewModifyProp(&Gadget1,Win,NULL,pInf->Flags,(USHORT)0,(USHORT)newPot,(USHORT)0,(USHORT)newBody,1);
knob_modified = 0;
}
}
SetPropKnob()
{
register ED *ep = Ep;
register struct PropInfo *pInf = &Gadget1SInfo;
register USHORT px,py;
register USHORT ky_start,ky_end;
register USHORT kHeight,cHeight;
register ULONG newPot;
cHeight = pInf->CHeight-5;
px = Win->Width-12;
py = 22;
newPot = 0xFFFF * ep->Topline / ((ep->Lines-Rows > 1) ? ep->Lines-Rows - 1 : 1);
pInf->VertBody = 0xFFFF * ((Rows < ep->Lines) ? Rows : ep->Lines) / ep->Lines;
if(newPot > 0xffff)
newPot = 0xffff;
pInf->VertPot = newPot;
kHeight = cHeight * (long)pInf->VertBody / 0xffff;
if(kHeight < 3)
kHeight = 3;
if(kHeight >= cHeight)
kHeight = cHeight - 1;
ky_start = py + (cHeight-kHeight) * newPot / 0xffff;
ky_end = ky_start + kHeight;
if(ky_end - ky_start < 1)
ky_end = ky_start +1;
SetAPen(Rp,0);
RectFill(Rp,px,py,px+9,py+cHeight);
SetAPen(Rp,1);
RectFill(Rp,px,ky_start,px+7,ky_end);
knob_modified = 1;
}
Gad(mess) /* handle gadgets put it in main.c */
struct IntuiMessage *mess;
{
register struct Gadget *gad;
register int gadid;
register ED *ep = Ep;
register long n;
register short diff;
if(!(Win->Flags & WINDOWACTIVE)) {
set_prop();
}
gad = (struct Gadget *)mess->IAddress;
gadid = gad->GadgetID;
switch(gadid) {
case 1: /* scroll bar */
n = (ep->Lines-Rows) * Gadget1SInfo.VertPot / 0xFFFF;
if (n < 0)
n = 0;
else
if (n >= ep->Lines-Rows)
n = (ep->Lines-Rows < 1 ? 1 : ep->Lines-Rows) - 1;
diff = ep->Topline - n;
if(diff) {
text_cursor(0);
text_sync();
ep->Line = n + (ep->Line - ep->Topline);
ep->Topline = n;
if(diff > 0) {
if (diff < (Rows << 1) / 3 ) {
ScrollRaster(Rp,0,-Ysize*diff,COL(0),ROW(0),COL(Columns)-1,ROW(Rows)-1);
text_displayseg(0,diff);
text_load();
text_sync();
text_cursor(1);
break;
}
} else {
diff = -diff;
if (diff < (Rows << 1) / 3 ) {
ScrollRaster(Rp,0,Ysize*diff,COL(0),ROW(0),COL(Columns)-1,ROW(Rows)-1);
text_displayseg(Rows-diff,diff);
text_load();
text_sync();
text_cursor(1);
break;
}
}
text_load();
if (!text_sync())
text_redisplay();
text_cursor(1);
}
if(knob_modified)
set_prop();
break;
case 2: /* arrow up */
text_cursor(0);
do_scrollup();
text_cursor(1);
break;
case 3: /* arrow down */
text_cursor(0);
do_scrolldown();
text_cursor(1);
break;
}
}